//
//  SleepHeartPatternsController.swift
//  DaRings
//
//  Created by 易先生 on 2022/11/4.
//

import UIKit
import MYModule

class SleepHeartPatternsController: ViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        navigation.item.title = "sleep_heart_rate_patterns".language
        navigation.bar.backgroundColor = UIColor.background
    }
    
    override func makeUI() {
        super.makeUI()
        
        view.backgroundColor = UIColor.background
        view.addSubview(scrollView)
        scrollView.addSubview(contentView)
        contentView.addSubview(nighttimeContentlabel)
        contentView.addSubview(restingHeartTitlelabel)
        contentView.addSubview(restingHeartContentlabel)
        contentView.addSubview(lookingStackView)
        contentView.addSubview(hammockView)
        contentView.addSubview(downwardView)
        contentView.addSubview(hillView)

        scrollView.snp.makeConstraints { make in
            make.top.equalTo(topLayoutGuide.snp.bottom)
            make.leading.trailing.bottom.equalToSuperview()
        }
        
        contentView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
            make.centerX.equalToSuperview()
        }
        
        nighttimeContentlabel.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(12)
            make.leading.equalToSuperview().offset(20)
            make.centerX.equalToSuperview()
        }
        
        restingHeartTitlelabel.snp.makeConstraints { make in
            make.top.equalTo(nighttimeContentlabel.snp.bottom).offset(30)
            make.leading.equalToSuperview().offset(20)
            make.centerX.equalToSuperview()
        }
        
        restingHeartContentlabel.snp.makeConstraints { make in
            make.top.equalTo(restingHeartTitlelabel.snp.bottom).offset(16)
            make.leading.equalToSuperview().offset(20)
            make.centerX.equalToSuperview()
        }
        
        lookingStackView.snp.makeConstraints { make in
            make.top.equalTo(restingHeartContentlabel.snp.bottom).offset(16)
            make.leading.equalToSuperview().offset(20)
            make.centerX.equalToSuperview()
        }
        
        hammockView.snp.makeConstraints { make in
            make.top.equalTo(lookingStackView.snp.bottom).offset(30)
            make.leading.trailing.equalToSuperview()
            make.centerX.equalToSuperview()
        }
        
        downwardView.snp.makeConstraints { make in
            make.top.equalTo(hammockView.snp.bottom).offset(30)
            make.leading.trailing.equalToSuperview()
        }

        hillView.snp.makeConstraints { make in
            make.top.equalTo(downwardView.snp.bottom).offset(30)
            make.leading.trailing.equalToSuperview()
            make.bottom.equalToSuperview().offset(-46)
        }
        
        let contents = ["sleep_heart_rate_patterns_when_looking_content_1".language,
                        "sleep_heart_rate_patterns_when_looking_content_2".language,
                        "sleep_heart_rate_patterns_when_looking_content_3".language,
                        "sleep_heart_rate_patterns_when_looking_content_4".language,
                        "sleep_heart_rate_patterns_when_looking_content_5".language
        ]
        
        contents.forEach { content in
            let lookingContentlabel = Label()
            lookingContentlabel.font = Fonts.systemFont(ofSize: 14)
            lookingContentlabel.textColor = UIColor.assist_A9A9A9
            lookingContentlabel.attributedText = contParagraph(content: content)
            lookingContentlabel.numberOfLines = 0
            lookingStackView.addArrangedSubview(lookingContentlabel)
        }
    }
    
    private func contParagraph(content: String) -> NSMutableAttributedString {
        return content.toAttributed
            .font(Fonts.systemFont(ofSize: 14))
            .foregroundColor(UIColor.assist_A9A9A9)
            .paragraph(setup: {$0.lineSpacing = 6})
            .rawValue
    }
    
    public lazy var scrollView: ScrollView = {
        let view = ScrollView()
        view.showsVerticalScrollIndicator = false
        view.backgroundColor = UIColor.background
        view.bounces = false
        return view
    }()

    public lazy var contentView: View = {
        let view = View()
        view.backgroundColor = UIColor.background
        return view
    }()
    
    private lazy var nighttimeContentlabel: Label = {
        let nighttimeContentlabel = Label()
        nighttimeContentlabel.font = Fonts.systemFont(ofSize: 14)
        nighttimeContentlabel.textColor = UIColor.assist_A9A9A9
        nighttimeContentlabel.numberOfLines = 0
        nighttimeContentlabel.attributedText = contParagraph(content: "sleep_heart_rate_patterns_your_nighttime_resting_content".language)
        return nighttimeContentlabel
    }()
    
    private lazy var restingHeartTitlelabel: Label = {
        let restingHeartTitlelabel = Label()
        restingHeartTitlelabel.font = Fonts.systemFont(ofSize: 14)
        restingHeartTitlelabel.textColor = UIColor.assist_222222
        restingHeartTitlelabel.text = "sleep_heart_rate_patterns_resting_during_title".language
        restingHeartTitlelabel.numberOfLines = 0
        return restingHeartTitlelabel
    }()
    
    private lazy var restingHeartContentlabel: Label = {
        let restingHeartContentlabel = Label()
        restingHeartContentlabel.font = Fonts.systemFont(ofSize: 14)
        restingHeartContentlabel.textColor = UIColor.assist_A9A9A9
        restingHeartContentlabel.attributedText = contParagraph(content: "sleep_heart_rate_patterns_resting_during_content".language)
        restingHeartContentlabel.numberOfLines = 0
        return restingHeartContentlabel
    }()
    
    private lazy var lookingStackView: StackView = {
        let lookingStackView = StackView()
        lookingStackView.axis = .vertical
        lookingStackView.spacing = 10
        return lookingStackView
    }()
    
    private lazy var hammockView: SleepHeartRatePatternsView = {
        let hammockView = SleepHeartRatePatternsView()
        hammockView.bind(to: "sleep_heart_rate_patterns_hammock_title".language,
                         subitTitle: "sleep_heart_rate_patterns_hammock_subit_title".language,
                         icon: "img_sleep_patterns_1",
                         contents: ["sleep_heart_rate_patterns_hammock_content_1".language,
                                    "sleep_heart_rate_patterns_hammock_content_2".language,
                                    "sleep_heart_rate_patterns_hammock_content_3".language,
                                    "sleep_heart_rate_patterns_hammock_content_4".language
                                   ])
        return hammockView
    }()
    
    private lazy var downwardView: SleepHeartRatePatternsView = {
        let downwardView = SleepHeartRatePatternsView()
        downwardView.bind(to: "sleep_heart_rate_patterns_downward_title".language,
                         subitTitle: "sleep_heart_rate_patterns_downward_subit_title".language,
                         icon: "img_sleep_patterns_2",
                          contents: ["sleep_heart_rate_patterns_downward_content_1".language,
                                     "sleep_heart_rate_patterns_downward_content_2".language
                                    ])
        return downwardView
    }()
    
    private lazy var hillView: SleepHeartRatePatternsView = {
        let hillView = SleepHeartRatePatternsView()
        hillView.bind(to: "sleep_heart_rate_patterns_hill_title".language,
                         subitTitle: "sleep_heart_rate_patterns_hill_subit_title".language,
                         icon: "img_sleep_patterns_3",
                      contents: ["sleep_heart_rate_patterns_hill_subit_content_1".language,
                                 "sleep_heart_rate_patterns_hill_subit_content_2".language
                                ])
        return hillView
    }()
}
